(function(){
    _$(document).ready(function(){
        function App(){};
        App.prototype.ajaxFn=function(){
            _$.post('/getuserHeadimg',function(data){
                console.log(data);
                if(data['code']==1){
                    var userinfo=data['info']['userinfo'];
                    var username=data['info']['username'];
                    _$("#mycover").attr('src',userinfo['imgurl']).attr('alt',userinfo['nickname']+"的头像");
                    _$("#nickname").html(userinfo['nickname']);
                    if(userinfo['userLevel']==1){
                        _$("#huiy,#huiy1").attr({'aria-label':'普通用户','class':'icon-level-1'});
                    }else if(userinfo['userLevel']==2){
                        _$("#huiy,#huiy1").attr({'aria-label':'普通会员','class':'icon-level-2'});
                    }else if(userinfo['userLevel']==3){
                        _$("#huiy,#huiy1").attr({'aria-label':'高级会员','class':'icon-level-3'});
                    }else if(userinfo['userLevel']==4){
                        _$("#huiy,#huiy1").attr({'aria-label':'初级VIP','class':'icon-level-4'});
                    }else if(userinfo['userLevel']==5){
                        _$("#huiy,#huiy1").attr({'aria-label':'高级VIP','class':'icon-level-5'});
                    }
                    _$("#month").html(userinfo['month']);
                    if(userinfo['account']>=10000){
                        userinfo['account']=(userinfo['account']/10000).toFixed(2)+"万";
                    }
                    _$("#account").html(userinfo['account']);
                    _$("#recomm").html(parseInt(userinfo['recomm']['nan'])+parseInt(userinfo['recomm']['nv']));
                }
            });
        };
        App.prototype.eventFn=function(){
            //菜单下拉
            _$("#openGuide").on("click",function(){
                var key=_$(this).attr('data-key');
                var that=_$(this);
                if(key==1){
                    _$(this).attr('data-key','0').addClass('icon-x').removeClass('icon-more-w');
                    _$("#guide").animate({'height':'100%'},300);
                    _$("#header").removeClass('header-r');
                    _$(".header .header-back i").removeClass('w');
                    _$(".btn-group-cell").css('color','#333');
                    _$("#openSearchPopup").removeClass('icon-search-w');
                }else{
                    _$(this).attr('data-key','1');
                    _$("#guide").animate({'height':'0'},300);
                    setTimeout(function(){
                        that.removeClass('icon-x').addClass('icon-more-w');
                        _$("#header").addClass('header-r');
                        _$(".header-back i").addClass('w');
                        _$(".header .btn-group-cell").css('color','#fff');
                        _$("#openSearchPopup").addClass('icon-search-w');
                    },300);
                }
            });
        };
        App.prototype.init=function(){
            //事件调用
            this.ajaxFn();
            this.eventFn();
        };
        //程序初始化
        new App().init();
    })
})();
